#pragma once

// D3D Application program. Main game/simulation will inherit from this base-line code.
// Mostly a copy of d3dApp.h by Frank Luna (C) 2005, but built from the ground-up
// myself to gain a full understanding of how the code is put together and what
// everything is meant to do

// Stupid bug: need to include winsock2.h before windows.h, OR define this in order to avoid some huge compiler errors.
#define _WINSOCKAPI_

#include <d3d9.h>
#include <d3dx9.h>
#include <string>

#define WINDOWED_DEFAULTWIDTH	1280
#define WINDOWED_DEFAULTHEIGHT	720

#define DT_MAX					0.0045f

class d3dapplication
{
public:
	d3dapplication(HINSTANCE hInstance,
		std::string caption,
		D3DDEVTYPE devType,
		DWORD requestedVP);
	virtual ~d3dapplication(void);

	HINSTANCE	getInstance() {return mhInst;};
	HWND		getMainWnd() {return mhMainWnd;};

	D3DPRESENT_PARAMETERS	getD3dPP() { return	mD3DPP;	};


	// how these methods function will depend on what the inheriting program
	// wants to create. Since this base-line application doesn't create anything
	// there's no need to do anything in these functions.
	virtual bool checkDeviceCaps()	{return true;};
	virtual void OnLostDevice()		{}
	virtual void OnResetDevice()	{}
	virtual void Update(float dt)	{}
	virtual void Render()			{}

	virtual void InitMainWindow();
	virtual void InitD3D();
	virtual int Run();
	virtual LRESULT msgProc(UINT msg, WPARAM wParam, LPARAM lParam);

	void EnableFullScreenMode(bool enableFSM);
	bool IsDeviceLost();

protected:
	HINSTANCE	mhInst;
	HWND		mhMainWnd;

	std::string	mMainWndCaption;
	D3DDEVTYPE	mDevType;
	DWORD		mRequestedVP;

	// used to tell the system to pause
	bool mAppPaused;
	bool mAppPausedLastFrame;

	IDirect3D9*	mD3DObject;
	D3DPRESENT_PARAMETERS	mD3DPP;
};

// create some global variables
// should only ever need one application and one device
extern d3dapplication*		gD3DApplication;
extern IDirect3DDevice9*	gD3DDevice;
